package com.yyfax.ph.progress.search;

import android.content.res.Resources;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.yyfax.common.adapter.BaseRecycleAdapter;
import com.yyfax.common.recyclerview.IViewHolder;
import com.yyfax.common.recyclerview.OnItemClickListener;
import com.yyfax.ph.R;
import com.yyfax.ph.common.utils.Constants;

public class ProgressAdapter extends BaseRecycleAdapter<ProgressModel.ProgressBean> {

	private OnItemClickListener<ProgressModel.ProgressBean> mClickListener;

	public ProgressAdapter(OnItemClickListener listener) {
		mClickListener = listener;
	}


	@Override
	public IViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.progress_item_layout, null);
		return new ViewHolder(view);

	}

	@Override
	public void onBindViewHolder(final IViewHolder holder, final int position) {
		final ViewHolder view = (ViewHolder) holder;
		final ProgressModel.ProgressBean progressBean = getDataSet().get(position);
		view.mNameTv.setText(progressBean.rcmdName);
		view.mImgNameTv.setText(progressBean.rcmdName.substring(0, 1));
		view.mDateTv.setText(progressBean.referDate);
		view.mStatusTv.setText(progressBean.status);
		Resources resources = view.itemView.getContext().getResources();
		//进度查询头像
		if (TextUtils.equals(progressBean.avatar, Constants.PROGRESS_ICON_MAN)) {
			view.mImg.setImageDrawable(resources.getDrawable(R.drawable.icon_man));

		} else if (TextUtils.equals(progressBean.avatar, Constants.PROGRESS_ICON_WOMAN)) {
			view.mImg.setImageDrawable(resources.getDrawable(R.drawable.icon_woman));
		} else {
			view.mImgNameTv.setText(null);
			view.mImg.setImageDrawable(resources.getDrawable(R.drawable.icon_logo_las));
		}

		//进度查询状态样式
		if (TextUtils.equals(progressBean.statusType, Constants.PROGRESS_DISABLE)) {//置灰状态
			int color = resources.getColor(R.color.color_999999);
			view.mDateTv.setTextColor(color);
			view.mNameTv.setTextColor(color);
			view.mStatusTv.setTextColor(color);
			view.mRightArrowIv.setVisibility(View.GONE);
			view.mContentLayout.setOnClickListener(null);
			view.mWaitingProcessIv.setVisibility(View.GONE);
		} else {//正常或者代办状态
			int color = resources.getColor(R.color.color_262930);
			view.mDateTv.setTextColor(resources.getColor(R.color.color_666666));
			view.mNameTv.setTextColor(color);
			view.mStatusTv.setTextColor(color);
			view.mRightArrowIv.setVisibility(View.VISIBLE);
			view.mContentLayout.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View arg0) {
					mClickListener.onItemClick(position, progressBean, view.mContentLayout);
				}
			});
			if (TextUtils.equals(progressBean.statusType, Constants.PROGRESS_WAIT_TO_DEAL_WITH)) {//待办状态，显示待办图标
				view.mWaitingProcessIv.setVisibility(View.VISIBLE);
			} else {//正常状态，隐藏待办图标
				view.mWaitingProcessIv.setVisibility(View.GONE);

			}
		}

		//如果是高分
		if (progressBean.highMark) {
			view.mHighScoreCustomerIv.setVisibility(View.VISIBLE);
		} else {
			view.mHighScoreCustomerIv.setVisibility(View.GONE);
		}


	}

	@Override
	public int getItemCount() {
		return getCount();
	}

	static class ViewHolder extends IViewHolder {
		@BindView(R.id.img)
		ImageView mImg;
		@BindView(R.id.img_name_tv)
		TextView mImgNameTv;
		@BindView(R.id.name_tv)
		TextView mNameTv;
		@BindView(R.id.date_tv)
		TextView mDateTv;
		@BindView(R.id.status_tv)
		TextView mStatusTv;
		@BindView(R.id.waiting_process_iv)
		ImageView mWaitingProcessIv;
		@BindView(R.id.right_arrow_iv)
		ImageView mRightArrowIv;
		@BindView(R.id.content_layout)
		RelativeLayout mContentLayout;
		@BindView(R.id.high_score_customer_iv)
		ImageView mHighScoreCustomerIv;

		ViewHolder(View view) {
			super(view);
			ButterKnife.bind(this, view);
		}
	}
}